package com.gp.gback.system.store.service.impl;


import com.gp.gback.system.common.annotation.APIMethod;
import com.gp.gback.system.common.annotation.SoaService;
import com.gp.gback.system.constants.SystemConstants;
import com.gp.gback.system.store.constants.StorageConstatns;
import com.gp.gback.system.store.dal.dao.StoreInfoDao;
import com.gp.gback.system.store.dal.po.StoreInfoPo;
import com.gp.gback.system.store.dto.StoreCateInfoDto;
import com.gp.gback.system.store.dto.StoreCityInfoDto;
import com.gp.gback.system.store.dto.StoreInfoQueryDto;
import com.gp.gback.system.store.dto.StoreOperationTypeDto;
import com.gp.gback.system.store.service.StoreInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by fox_lin on 17/3/31.
 */
@SoaService
@RequestMapping("/storeInfoService")
public class StoreInfoServiceImpl implements StoreInfoService {

    @Autowired
    private StoreInfoDao storeInfoDao;

    @APIMethod(name = "添加门店信息", category = SystemConstants.SoaApiCategory.STORE, apiUsers = ("ALL"), desc = "添加门店信息", authors = "Fox.Lin")
    @RequestMapping("/addStoreInfo")
    public void addStoreInfo(StoreInfoPo storeInfoPo){
        storeInfoDao.add(storeInfoPo);
    }

    @APIMethod(name = "查询门店信息", category = SystemConstants.SoaApiCategory.STORE, apiUsers = ("ALL"), desc = "查询门店信息", authors = "Fox.Lin")
    @RequestMapping("/query")
    public List<StoreInfoPo> query(StoreInfoQueryDto storeInfoQuery) {

        return storeInfoDao.query(storeInfoQuery);
    }

    @APIMethod(name = "查询所有门店城市", category = SystemConstants.SoaApiCategory.STORE, apiUsers = ("ALL"), desc = "查询所有门店城市", authors = "Fox.Lin")
    @RequestMapping("/getStoreCity")
    public List<StoreCityInfoDto> getStoreCity(){
        return  storeInfoDao.queryStoreCity();
    }

    @APIMethod(name = "查询所有门店分类", category = SystemConstants.SoaApiCategory.STORE, apiUsers = ("ALL"), desc = "查询所有门店分类", authors = "Fox.Lin")
    @RequestMapping("/getStoreCate")
    public List<StoreCateInfoDto> getStoreCate(){
        return  storeInfoDao.queryStoreCate();
    }

    @APIMethod(name = "查询所有门店经营方式", category = SystemConstants.SoaApiCategory.STORE, apiUsers = ("ALL"), desc = "查询所有门店经营方式", authors = "Fox.Lin")
    @RequestMapping("/getStoreOperationType")
    public List<StoreOperationTypeDto> getStoreOperationType() {

        return Stream.of(StorageConstatns.StorageOperationType.values()).map(item->new StoreOperationTypeDto(item.getTypeCode(),item.getTypeName())).collect(Collectors.toList());
    }
}
